package com.base.cloud.system.controller;

import com.base.cloud.system.service.BaseService;
import com.base.common.core.annotation.LogRunTime;
import com.base.common.spi.entitys.base.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping(value = "/test")
public class TestController {

    @RequestMapping(value = "/echo")
    @LogRunTime(value = "echo!!")
    public JsonResult<String> echo(HttpServletRequest request, String msg) {
        HttpSession session = request.getSession();
        log.info("调用了服务层echo方法，参数msg={}, sessionId={}, sessionValue={}"
                , msg, session.getId(), session.getAttribute("echo"));
        return new JsonResult<>(msg);
    }

    @Autowired
    DataSourceProperties dataSourceProperties;


//    @Autowired
//    DruidConfig druidConfig;

    @RequestMapping(value = "/dataResourceDetail")
    public JsonResult<String> dataResourceDetail(){
        System.out.println(dataSourceProperties.getUrl());
        System.out.println(dataSourceProperties.getUsername());
        System.out.println(dataSourceProperties.getPassword());

//        System.out.println(druidConfig.getMaxActive());
        return new JsonResult<>(dataSourceProperties.getUrl());
    }

    @Autowired
    BaseService baseService;

    @RequestMapping(value = "/getName")
    public JsonResult<String> getName(int id) {
        return new JsonResult<>(baseService.getName(1));
    }

}
